<!DOCTYPE html>
<html lang="en">
<head>
    <meta charset="UTF-8">
    <title>Title</title>
    <link rel="stylesheet" href="layui/css/layui.css">
    <link rel="stylesheet" href="css/style-user.css">
    <script src="layui/layui.js"></script>
</head>
<body>
    <table id="user" lay-filter="tableFilter"></table>
    <script type="text/html" id="bar">
        <a class="layui-btn layui-btn-xs layui-btn-danger" lay-event="upd">修改</a>
    </script>

    <script>
        layui.use(['table','layer'],function () {
            var table = layui.table;
            var layer = layui.layer;
            var $ = layui.$;
            //渲染表格
            table.render({
                elem:'#user',
                url:'user/selectUsers',
                cols:[[
                    {field:'userId',title:'ID',sort:true},
                    {field:'nickname',title:'昵称',sort:true},
                    {field:'email',title:'邮箱',sort:true},
                    {field:'status',title:'状态',templet:function (d) {
                            if(d.status==1){
                                return '正常'
                            }else {
                                return '用户被冻结'
                            }
                        }},
                    {field:'code',title:'激活码',sort:true},
                    {title:'操作',toolbar:'#bar'},
                ]]
            })
            //给修改操作绑定触发事件   tool行工具条被点击
            table.on('tool(tableFilter)',function (obj) {
                if(obj.event=='upd'){
                    $.ajax({
                        url:'user/updateUser',
                        data:'id='+obj.data.userId,
                        success:function (result) {
                            if(result.flag){
                                layer.msg('修改成功');
                                table.reload('user')
                            }
                        }
                    })
                }
            })
        })
    </script>
</body>
</html>